﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.IO;
using System.Drawing;
using System.Data.OleDb;

using NPOI.SS.UserModel;
using NPOI.HSSF.UserModel;
using NPOI.SS.Util;
using NPOI.Util;


namespace XJX.Page
{

    /// <summary>
    ///Helper 的摘要说明
    /// </summary>
    public class Helper
    {
        public Helper(){ }


        //上传文件到指定的目录
        public static void uploadFileToFolder(HttpPostedFile file, out string fn)
        {
            fn = "";

            if (file == null)
            {
                throw new Exception("请先选择文件！");
            }
            else
            {
                string fileName = file.FileName;/*获取文件名： C:\Documents and Settings\Administrator\桌面\123.jpg*/
                string suffix = fileName.Substring(fileName.LastIndexOf(".") + 1).ToLower();/*获取后缀名并转为小写： jpg*/
                int bytes = file.ContentLength;//获取文件的字节大小  
                //
                if (!(suffix == "doc"))
                    throw new Exception("有声图书只支持mp3格式文件！");
                if (bytes > 1024 * 1024 * 50)
                    throw new Exception("文件最大只能传50M");

                string newfileName = DateTime.Now.ToString("yyyyMMddHHmmss");
                string fileDir = HttpContext.Current.Server.MapPath("~/upload/mp3/");
                if (!Directory.Exists(fileDir))
                {
                    Directory.CreateDirectory(fileDir);
                }

                string saveDir = fileDir + newfileName + "." + suffix;

                file.SaveAs(saveDir);//保存mp3

                fn = newfileName + "." + suffix;
            }

        }



    }



}